﻿using FluentNHibernate.Mapping;
using Journal.Domain.Models;

namespace Journal.NHibernate.Mappings
{
    public class PermissionMap : ClassMap<Permission>
    {
        public PermissionMap()
        {
            Id(x => x.Id).UnsavedValue(0).GeneratedBy.Identity();
            Map(x => x.Name).Length(50).Not.Nullable();
            HasManyToMany(m => m.Sections).Table("PermissionToSection").ParentKeyColumn("PermissionId").ChildKeyColumn("SectionId").Cascade.None();
            HasManyToMany(m => m.Users).Table("PermissionToUser").ParentKeyColumn("PermissionId").ChildKeyColumn("UserId").Cascade.None();
        }
    }
}